package test.se.fk.klistret.extension.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import se.fk.matrix.konfiguration.Konfiguration;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:Spring.cfg.xml" })
@ActiveProfiles(profiles = { "development", "ivy" })
public class KonfigurationService {

	@Autowired
	private se.fk.klistret.extension.service.KonfigurationService konfigurationService;

	private JAXBContext jaxbContext;

	@Before
	public void setUp() throws Exception {
		jaxbContext = JAXBContext.newInstance(new Class[] {
				se.fk.matrix.konfiguration.Konfiguration.class,
				fkit.applikation.deployment.Manifest.class });
	}

	@Test
	public void register() throws UnsupportedEncodingException,
			FileNotFoundException, JAXBException {
		InputStreamReader isr = new InputStreamReader(
				new FileInputStream(
						new File(
								"C:\\workshop\\fk-klistret-extensions\\Klistret Extension\\configuration\\example\\IKO_0023_B01.xml")),
				"UTF-8");
		Konfiguration konfiguration = (Konfiguration) jaxbContext
				.createUnmarshaller().unmarshal(isr);

		konfigurationService.process(konfiguration);
	}
}
